package com.seed.web.struts.sysmanager;

import javax.annotation.Resource;

import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Controller;

import com.seed.commons.dbquery.PageViewForSQL;
import com.seed.service.sysmanager.IOrganization;
import com.seed.web.core.BaseActionSupport;
import com.seed.web.form.sysmanager.OrganizationForm;

@Controller
@Scope("prototype")
public class OrganizationAction extends BaseActionSupport{

	private static final long serialVersionUID = 1L;

	private OrganizationForm org ;
	
	@Resource(name="pageViewForSQL")
	private PageViewForSQL pv ;
	
	public PageViewForSQL getPv() {
		return pv;
	}

	public void setPv(PageViewForSQL pv) {
		this.pv = pv;
	}

	@Resource
	private IOrganization orgService ;
	
	public String saveOrg() throws Exception {
		boolean flag = this.orgService.saveOrg(org) ;
		if(flag) {
			saveMessage("机构添加成功！") ;
		} else {
			saveMessage("机构添加 失败！") ;
		}
		return "msg" ;
	}
	
	public String findOrgAll() throws Exception {
		
		this.getBaseform().getRequest().setAttribute("org", this.orgService.queryOrg()) ;
		
		if("adddept".equals(this.getBaseform().getType())) {
			return "adddept" ;
		} else {
			return "findorgall" ;
		}
	}
	
	public String findOrg() throws Exception {
		pv.setPageModel(this.orgService.getScrollData(pv.getFirstResult(), pv.getLineSize())) ;
		this.getBaseform().getRequest().setAttribute("scrolldata", pv) ;
		return "findorg" ;
	}
	
	public OrganizationForm getOrg() {
		return org;
	}

	public void setOrg(OrganizationForm org) {
		this.org = org;
	}
	
}
